import { create } from "zustand";
import { persist, subscribeWithSelector } from "zustand/middleware";

const initialFoodValue = {
  fish: 0,
};

export const useFoodStore = create(
  subscribeWithSelector(persist((set) => initialFoodValue, {name: 'food store'}))
);

export const addOneFish = () => {
  useFoodStore.setState((state) => ({ fish: state.fish + 1 }));
};

export const removeOneFish = () => {
  useFoodStore.setState((state) => ({ fish: state.fish - 1 }));
};

export const removeAllFish = () => {
  useFoodStore.setState((state) => ({ fish: 0 }));
};

// export const useFoodStore = create(subscribeWithSelector((set) =>
//     ({
//         fish: 0,
//         addOneFish: () => set(state => ({fish: state.fish + 1})),
//         removeOneFish: () => set(state => ({fish: state.fish - 1})),
//         removeAllFish: () => set(state => ({fish: 0})),
//     })
// ))
